'use strict';

const util = require('util');
const path = require('path');

const koa         = require('koa');
const logger      = require('koa-logger');
const views       = require('koa-views');
const koaBody     = require('koa-body');
const staticCache = require('koa-static-cache');
const Router      = require('koa-router');
const router      = new Router();

let app = koa();

require('./routes/routes')(router);

app
    .use(logger())
    .use(staticCache(path.join(__dirname, 'static'), {
        maxAge: 365 * 24 * 60 * 60
    }))
    .use(koaBody({formidable: {uploadDir: __dirname}}))
    .use(views(path.join(__dirname, '/views/pages'), {
        extension: 'jade'
    }))
    .use(router.routes())
    .listen(8080, ()=> {
        util.log('server listening at port 8080');
    });
